package com.soundShape.controllers.treatments
{
	import com.soundShape.events.SoundShapeEvent;
	import com.soundShape.model.ApplicationModel;
	import com.soundShape.vo.TreatmentVO;
	
	import mx.collections.ArrayCollection;
	
	import nz.co.codec.flexorm.criteria.Criteria;
	
	import org.swizframework.controller.AbstractController;

	public class TreatmentsController extends AbstractController
	{
		[Inject]
		public var applicationModel:ApplicationModel;
		
		public function TreatmentsController()
		{
		}
		
		[EventHandler(event="SoundShapeEvent.GET_TREATMENTS")]
		public function getTreatments(soundShapeEvent:SoundShapeEvent):void
		{
			var criteria:Criteria = applicationModel.entityManager.createCriteria(TreatmentVO);
			criteria.addEqualsCondition("customerID",soundShapeEvent.data);
			var treatments:ArrayCollection = this.applicationModel.entityManager.fetchCriteria(criteria);
			
			var soundShapeEvent:SoundShapeEvent = new SoundShapeEvent(SoundShapeEvent.SET_TREATMENTS);
			soundShapeEvent.data = treatments;
			this.dispatcher.dispatchEvent(soundShapeEvent);
			
		}
		
		[EventHandler(event="SoundShapeEvent.GET_TREATMENTS_PHOTO")]
		public function getTreatmentsPhoto(soundShapeEvent:SoundShapeEvent):void
		{
			var criteria:Criteria = applicationModel.entityManager.createCriteria(TreatmentVO);
			criteria.addEqualsCondition("customerID",soundShapeEvent.data);
			var treatments:ArrayCollection = this.applicationModel.entityManager.fetchCriteria(criteria);
			
			var soundShapeEvent:SoundShapeEvent = new SoundShapeEvent(SoundShapeEvent.SET_TREATMENTS_PHOTO);
			soundShapeEvent.data = treatments;
			this.dispatcher.dispatchEvent(soundShapeEvent);
			
		}
		
		[EventHandler(event="SoundShapeEvent.GET_TREATMENTS_COMPARISON")]
		public function getTreatmentsComparison(soundShapeEvent:SoundShapeEvent):void
		{
			var criteria:Criteria = applicationModel.entityManager.createCriteria(TreatmentVO);
			criteria.addEqualsCondition("customerID",soundShapeEvent.data);
			var treatments:ArrayCollection = this.applicationModel.entityManager.fetchCriteria(criteria);
			
			var soundShapeEvent:SoundShapeEvent = new SoundShapeEvent(SoundShapeEvent.SET_TREATMENTS_COMPARISON);
			soundShapeEvent.data = treatments;
			this.dispatcher.dispatchEvent(soundShapeEvent);
			
		}
	}
}